// 此例说明了async是单线程的，AlexZhang
var async = require('async');
var pushTask = function(name) {
  q.push(
    name,
    function(cb) {
      console.log('running: ' + name);
      console.log('waited 100ms');
      wait(10000);
      console.log('finished: ' + name);
    },
    function(err) {
      console.log('err: ' + name);
    }
  );
};
var wait = function(mils) {
  var now = new Date();
  while (new Date() - now <= mils);
};
var q = async.queue(function(name, task, callback) {
  console.log('processing task: ' + name);
  task(callback);
}, 3);
pushTask('t1');
pushTask('t2');
pushTask('t3');
pushTask('t4');
pushTask('t5');
pushTask('t6');
pushTask('t7');
pushTask('t8');
console.log('waited 1000ms');
